<?php
require('../database/db.php');
$mysql=new mysql();
error_reporting(0);
// 分页
if($_REQUEST['page']!="" && $_REQUEST['pagesize']!=""){
	$de=$_REQUEST['page']*$_REQUEST['pagesize'];
	$size=$_REQUEST['pagesize'];
}else{
	$de=0;
	$size=10;
}
// 分页 end
// 需传参数
$cityid=$_REQUEST['cityid'];
// 需传参数 end

	$sql="SELECT * FROM goods WHERE xihuan=1 AND goods.check=1 ORDER BY goodsid DESC limit $de,$size";
	$goods=$mysql->getAll($sql);
	$len=count($goods);
	for($i=0;$i<$len;$i++){
		// 设置默认图
		$images = explode(',', $goods[$i]['images']);
		if ($images[$goods[$i][defaultImgOrd]] !='') {
			$defaultImg = $images[$goods[$i][defaultImgOrd]];
		}else{
			$defaultImg = $image[0];
		}
		$goods[$i][mainimages] = $defaultImg;
		// 设置默认图 end
		
		$goodsid =$goods[$i][goodsid];
		$sql2 = "select * from goodsselect where goodsid=$goodsid and number>0";
		$goods[$i][goodsselect]=$mysql->getAll($sql2);

		$goods[$i][number] = $goods[$i][xiaoliang];
		$goods[$i][name] = $goods[$i][title];
		$goods[$i][intro] = $goods[$i][summary];
		$goods[$i][id] = $goods[$i][goodsid];
		$goods[$i][content] = 1;
		$goods[$i][qq] = $goods[$i][qq];

	}
	$arr = array('code' => 200, 'tip' =>'查询成功' ,'goods' =>$goods);

echo json_encode($arr);
?>